package DButlit;

import java.sql.*;

import static DButlit.Bedding.getConn;

public class GongJu {
    public static int updata(String sql , Object...keys){
        int num  = 0;
        try {
            Connection coon = getConn();
            PreparedStatement pre = coon.prepareStatement(sql);
            for (int i = 0; i < keys.length; i++) {
                pre.setObject((i + 1), keys[i]);
            }
            num = pre.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return num;
    }

    public static ResultSet select(String sql,Object...keys){
        ResultSet res = null;
        try {
            Connection conn = getConn();
            PreparedStatement pre = conn.prepareStatement(sql);
            for (int i = 0; i < keys.length; i++) {
                pre.setObject((i + 1), keys[i]);
            }
            res = pre.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return res;
    }
}
